<template>
  <div class="app-container" style="background: #FFFFFF;">

    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="渠道名称" prop="deaName">
        <el-input v-model="queryParams.deaName" placeholder="请输入渠道名称" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="BD销售" prop="other2">
        <el-select v-model="queryParams.other2" style="width: 90%;" filterable placeholder="业务员" clearable>
          <el-option v-for="item in ywyOptions" :key="item.userId" :label="item.nickName"
            :value="item.userId.toString()"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="技术员" prop="other5">
        <el-select v-model="queryParams.other5" style="width: 90%;" filterable placeholder="技术员" clearable>
          <el-option v-for="item in jsyOption" :key="item.userId" :label="item.nickName"
            :value="item.userId.toString()"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="手机号码" prop="deaTel" v-if="false">
        <el-input v-model="queryParams.deaTel" placeholder="请输入手机号码" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="电子邮箱" prop="deaEmail" v-if="false">
        <el-input v-model="queryParams.deaEmail" placeholder="请输入电子邮箱" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="订单时间">
        <el-date-picker v-model="dateRange[0]" type="date" value-format="yyyy-MM-dd" placeholder="开始时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="">
        <span>至</span>
      </el-form-item>
      <el-form-item label="">
        <el-date-picker v-model="dateRange[1]" type="date" value-format="yyyy-MM-dd" placeholder="结束时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="客户经理" prop="accountManagerName" v-if="false">
        <el-input v-model="queryParams.accountManagerName" placeholder="请输入客户经理" clearable
          @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['DealerMain:dealerhw:add']">新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-edit" size="mini" :disabled="single" @click="handleUpdate"
          v-hasPermi="['DealerMain:dealerhw:edit']">修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="danger" plain icon="el-icon-delete" size="mini" :disabled="multiple" @click="handleDelete"
          v-hasPermi="['DealerMain:dealerhw:remove']">删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport"
          v-hasPermi="['DealerMain:dealerhw:export']">导出</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-refresh-right" size="mini" @click="tbDeal(1)"
          v-hasPermi="['DealerMain:dealerhw:tbqd']">同步渠道信息</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="success" plain icon="el-icon-refresh-right" size="mini" @click="tbDeal(2)" title="近一个月"
          v-hasPermi="['DealerMain:dealerhw:tbqd']">同步近期渠道</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table border="" v-loading="loading" :data="dealerList" @selection-change="handleSelectionChange"
      :header-cell-style="{ background: '#eef1f6', color: '#606266' }" ref="fileTable">
      <el-table-column type="selection" width="55" align="center" @selection-change="handleSelectionChange" />
      <el-table-column label="经销商id" align="center" prop="deaId" v-if="false" />
      <el-table-column label="渠道名称/帐号" align="left" prop="deaName" width="350px">
        <template slot-scope="scope">
          <el-tooltip placement="top">
            <div slot="content">{{ scope.row.deaName }}<br />{{ scope.row.deaUser }}</div>
            <div>
              <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">{{ scope.row.deaName }}</div>
              <span style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">
                {{ scope.row.deaUser }}
              </span>
            </div>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="等级" align="center" prop="" width="80">
        V0
      </el-table-column>
      <el-table-column label="帐户余额(¥)" align="center" prop="a1" v-if="false">
        <template>
          <span style="white-space: pre-wrap;">
            0.00
          </span>
        </template>
      </el-table-column>

      <el-table-column label="手机号码" align="center" prop="deaTel" width="100" />

      <el-table-column label="电子邮箱" align="center" prop="deaEmail" v-if="false" />

      <el-table-column label="客户经理" align="center" prop="accountManagerName" v-if="false" />

      <el-table-column label="经销商类型" align="center" prop="deaType" v-if="false">
        <template slot-scope="scope">
          <span style="white-space: pre-wrap;">
            {{ scope.row.deaType == '1' ? '一级经销商' : '二级经销商' }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="关联时间" align="center" prop="createTime" width="100">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.associatedOn, "{y}-{m}-{d}") }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="left" prop="other1" v-if="false">
        <template slot-scope="scope">
          <span slot="reference" v-if="scope.row.other1 == 3">
            <div class="dotClass" style="background-color: blue;"> </div>
            <div style="float: left; margin-left: 10px;">已认证</div>
          </span>
          <span slot="reference" v-if="scope.row.other1 == 1">
            <div class="dotClass" style="background-color: springgreen;"> </div>
            <div style="float: left; margin-left: 10px;">已关联</div>
          </span>
          <span v-if="scope.row.other1 == null">
            <div class="dotClass" style="background-color: red;"> </div>
            <div style="float: left;  margin-left: 10px;">未关联</div>
          </span>

        </template>
      </el-table-column>
      <el-table-column label="海纳渠道" align="center" key="status" width="140" v-if="false">
        <template slot-scope="scope">
          <el-switch v-model="scope.row.status" active-value="0" inactive-value="1"
            @change="handleStatusChange(scope.row)"></el-switch>
        </template>
      </el-table-column>
      <!-- <el-table-column label="负责业务员" align="left" prop="userName" v-if="false">
        <template slot-scope="scope" >
          <el-tooltip  placement="top" >
            <div slot="content">{{ scope.row. nickName}}<br/>{{scope.row.userName}}</div>
              <div>
              <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;" >{{scope.row.nickName}}</div>
              <span style="white-space: pre-wrap;">
              {{scope.row.userName}}
              </span>
            </div>
        </el-tooltip>
        </template>
      </el-table-column> -->
      <el-table-column label="负责业务员" align="left" prop="showaccountName">
        <template slot-scope="scope">
          <el-tooltip placement="top">
            <div slot="content">{{ scope.row.showaccountName }}</div>
            <div>
              <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">{{ scope.row.showaccountName }}
              </div>
            </div>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="负责技术员" align="left" prop="showjs">
        <template slot-scope="scope">
          <el-tooltip placement="top">
            <div slot="content">{{ scope.row.showjs }}</div>
            <div>
              <div style="overflow: hidden; white-space: nowrap; text-overflow: ellipsis;">{{ scope.row.showjs }}
              </div>
            </div>
          </el-tooltip>
        </template>
      </el-table-column>
      <el-table-column label="客户数量" align="center" prop="khsl" width="120" v-if="false">
        <template slot-scope="scope">
          <span style="white-space: pre-wrap;">
            {{ scope.row.khsl }} 个
          </span>
        </template>
      </el-table-column>
      <!-- <el-table-column label="创建人" align="center" prop="createUser" />
      <el-table-column label="修改人" align="center" prop="editUser" /> -->
      <el-table-column label="订单金额" align="right" prop="je" width="120">
        <template slot-scope="scope">
          {{ toFixed(scope.row.je) }}
        </template>
      </el-table-column>
      <el-table-column label="实付金额" align="right" prop="sf" width="120">
        <template slot-scope="scope">
          {{ toFixed(scope.row.sf) }}
        </template>
      </el-table-column>
      <el-table-column label="排名" align="center" width="80">
        <template slot-scope="scope">
          <i class="el-icon-trophy" title="TOP1" style="color: #ffbb00;font-size: 22px;"
            v-if="(scope.$index + ((queryParams.pageNum - 1) * (queryParams.pageSize) + 1)) == 1"></i>
          <i class="el-icon-trophy-1" title="TOP2" style="color: #68c9e6;font-size: 22px;"
            v-else-if="(scope.$index + ((queryParams.pageNum - 1) * (queryParams.pageSize) + 1)) == 2"></i>
          <i class="el-icon-medal" title="TOP3" style="color: #50c996;font-size: 22px;"
            v-else-if="(scope.$index + ((queryParams.pageNum - 1) * (queryParams.pageSize) + 1)) == 3"></i>
          <i style="color: #b3560a;font-size: 18px;" v-else>{{ (scope.$index +
            ((queryParams.pageNum - 1) * (queryParams.pageSize) + 1)) }}</i>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="180px" fixed="right">
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['DealerMain:dealer:edit']"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['DealerMain:dealer:remove']"
            >删除</el-button> -->
          <el-button size="mini" type="text" icon="el-icon-warning-outline" @click="handlemark(scope.row)">详情</el-button>
          <el-button size="mini" type="text" @click="findkh(scope.row)">查看客户</el-button>
          <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)"
            v-hasPermi="['DealerMain:dealerhw:fp']">
            <el-button size="mini" type="text" icon="el-icon-d-arrow-right">分配</el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item command="handleywy" icon="el-icon-key">分配业务员</el-dropdown-item>
              <el-dropdown-item command="handlejsy" icon="el-icon-s-custom">分配技术员</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>

        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />

    <!-- 添加或修改一级经销商对话框 -->
    <el-dialog :title="title1" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="经销商" prop="deaName">
          <el-input v-model="form.deaName" placeholder="请输入经销商名称" />
        </el-form-item>
        <el-form-item label="经销商ID" prop="deaId" v-if="false">
          <el-input v-model="form.deaId" placeholder="请输入经销商名称" />
        </el-form-item>
        <el-form-item label="经销商类型" prop="dtype" v-if="false">
          <el-input v-model="form.dtype" placeholder="请输入经销商名称" />
        </el-form-item>
        <el-row>
          <el-col :span="12">
            <el-form-item label="登录名" prop="deaUser">
              <el-input v-model="form.deaUser" :disabled="deadis" placeholder="请输入登录名" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="密码" prop="deaPassword">
              <el-input v-model="form.deaPassword" placeholder="请输入密码" show-password />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="客户经理" prop="deaPeople">
              <el-input v-model="form.deaPeople" placeholder="请输入联系人" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="手机号码" prop="deaTel">
              <el-input v-model="form.deaTel" placeholder="请输入手机号码" />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="邮箱" prop="deaEmail">
              <el-input v-model="form.deaEmail" placeholder="请输入邮箱" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="启用状态">
              <el-radio-group v-model="form.deaState">
                <el-radio v-for="dict in dict.type.sys_normal_disable" :key="dict.value" :label="dict.value">{{ dict.label
                }}</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
        </el-row>
        <el-form-item label="公司地址" prop="deaAddress">
          <el-input v-model="form.deaAddress" type="textarea" placeholder="请输入公司地址" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 分配弹窗测试 -->
    <el-dialog :title="title" :visible.sync="open1" width="500px" append-to-body>
      <el-form :model="queryParamsUser" ref="queryFormUser" size="small" :inline="true" label-width="68px"
        @submit.native.prevent>
        <el-form-item label="姓名" prop="nickName">
          <el-input v-model="queryParamsUser.nickName" placeholder="请输入姓名" clearable
            @keyup.enter.native="handleUserQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleUserQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQueryUser">重置</el-button>
        </el-form-item>
      </el-form>
      <el-form label-width="80px">
        <el-table v-loading="loading" style="overflow: auto; " height="400px" :data="dealeruser"
          @selection-change="handleSelectionChangeUser" ref="multipleTable">
          <el-table-column type="selection" width="55" align="center" />
          <el-table-column label="编号" align="center" prop="userId" />
          <el-table-column label="帐号" align="center" prop="userName" />
          <el-table-column label="姓名" align="center" prop="nickName" />
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="ImportClick">确 定</el-button>
        <el-button @click="cancel1">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 设置详情弹窗-->
    <el-dialog :title="titlxq" :visible.sync="openmark" width="800px" append-to-body>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAddmark">新增</el-button>
        </el-col>
      </el-row>
      <el-form label-width="80px">
        <el-table border="" v-loading="loadingmark" :data="customerinfomarkList" height="400px"
          :header-cell-style="{ background: '#eef1f6', color: '#606266' }">

          <el-table-column label="用户编号" align="center" prop="id" v-if="false" />
          <el-table-column label="客户编号" align="center" prop="deaId" v-if="false" />
          <el-table-column label="备注信息" align="left" prop="mark" />
          <el-table-column label="添加人" align="center" prop="other5" width="80" />
          <el-table-column label="修改人" align="center" prop="editUser" v-if="false" />
          <el-table-column label="添加时间" align="center" prop="createSj" width="100">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createSj, '{y}-{m}-{d}') }}</span>
            </template>
          </el-table-column>

          <el-table-column label="修改时间" align="center" prop="editSj" v-if="false" />
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="120">
            <template slot-scope="scope">
              <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdatemark(scope.row)">修改</el-button>
              <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDeletemark(scope.row)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-form>
    </el-dialog>
    <!-- 添加或修改客户备注对话框 -->
    <el-dialog :title="titlemark" :visible.sync="openmarka" width="500px" append-to-body>
      <el-form ref="formmark" :model="formmark" :rules="rulesmark" label-width="80px">
        <el-form-item label="信息备注" prop="mark">
          <el-input v-model="formmark.mark" type="textarea" :rows="6" placeholder="请输入备注" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFormmark">确 定</el-button>
        <el-button @click="cancelmark">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import {

  selectyh,
  selectyhjs,
  listDealerph,
  getDealer,
  delDealer,
  addDealer,
  updateDealer,
  tblistDealer,
  changeDeaUserStatus,
} from "@/api/DealerMain/dealer";
import { listuser, listJsy, changeUserStatus } from "@/api/system/user";
import { listDealeruser } from "@/api/DealerUserMain/dealeruser";
import { GetMonA, GetMonB } from "@/api/public";
import { listDealeruserjs, getDealeruserjs, delDealeruserjs, addDealeruserjs, updateDealeruserjs } from "@/api/DealerMain/dealeruserjs";
import { listDealermark, getDealermark, delDealermark, addDealermark, updateDealermark } from "@/api/DealerMain/dealermark";
export default {

  dicts: ["sys_normal_disable", "sys_order_type"],
  name: "Dealer",
  data() {
    return {

      jsyOption: [],//技术员

      dateRange: [],
      deaval: {//分配时，传值的parm
        deaIdpa: null,
        deaIdpb: null,
        deaIdpc: null,
        deaId: null,
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],

      //分配业务员选中相关
      ywyid: [],//分配选中的业务员
      ywyname: [],
      ywycode: [],
      idsdeaid: '',
      title1: "",
      open1: false,
      queryParamsUser: {
        nickName: null,
      },
      deauserparm: {
        deaid: null,
        pageSize: 30,
      }, //获取选中业务员参数

      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,

      // 一级经销商表格数据
      dealerList: [],
      //经销商对应业务员列表数据
      dealeruser: [],
      // 弹出层标题
      title: "",
      ywyOptions: [],//业务员
      // 是否显示弹出层
      open: false,
      deadis: true,
      deatabname: '',//标签名称
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        deaName: null,
        deaUser: null,
        deaPassword: null,
        deaPeople: null,
        deaTel: null,
        deaEmail: null,
        deaAddress: null,
        deaType: null,

        createUser: null,
        editUser: null,
        editTime: null,
        other1: null,
        other2: null,
        other3: null,
        other4: null,
        other5: null,
        dtype: null,
      },

      //渠道详情相关
      loadingmark: true,
      customerinfomarkList: [],
      openmark: false,
      openmarka: false,
      titlxq: '',
      titlemark: '',
      // 查询参数
      queryParammark: {
        pageNum: 1,
        pageSize: 30,
        deaId: null,
        mark: null,
        other1: null,
        other2: null,
        other3: null,
        other4: null,
        other5: null,
        createUser: null,
        editUser: null,
        createSj: null,
        editSj: null
      },
      // 详情表单参数
      formmark: {},
      // 表单校验
      rulesmark: {
        mark: [
          { required: true, message: "备注不能为空", trigger: "blur" },
        ],
      },

      // 表单参数
      form: {},
      // 表单校验
      rules: {
        deaName: [
          { required: true, message: "经销商名称不能为空", trigger: "blur" },
          {
            min: 2,
            max: 20,
            message: "用户名称长度必须介于 2 和 50 之间",
            trigger: "blur",
          },
        ],
        deaUser: [
          { required: true, message: "用户名不能为空", trigger: "blur" },
        ],

        deaPassword: [
          { required: true, message: "用户密码不能为空", trigger: "blur" },
          {
            min: 5,
            max: 20,
            message: "用户密码长度必须介于 5 和 20 之间",
            trigger: "blur",
          },
        ],
        deaEmail: [
          {
            type: "email",
            message: "请输入正确的邮箱地址",
            trigger: ["blur", "change"],
          },
        ],
        deaTel: [
          { required: true, message: "手机号不能为空", trigger: "blur" },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur",
          },
        ],
      },
    };
  },
  created() {

    this.dateRange[0] = GetMonA(3);
    this.dateRange[1] = GetMonB();
    // this.queryParams.dtype = this.$route.query.a;//获取路由上的类型，一代，二代，华为二代

    // alert(this.queryParams.dtype);
    this.getList();
    //绑定业务员
    listuser(this.queryParamsUser).then(response => {
      this.ywyOptions = response.rows;
    });
    //绑定技术员
    listJsy().then((response1) => {
      this.jsyOption = response1.rows;
    });
  },
  methods: {
    //保留两位，不足补位
    toFixed(num) {
      return (Math.round(num * 100) / 100).toFixed(2);
    },
    handleClick(tab, event) {
      console.log(tab, event);
    },
    // 更多操作触发
    handleCommand(command, row) {
      switch (command) {
        case "handleywy":
          this.deafp(row);
          break;
        case "handlejsy":
          this.handlejsy(row);
          break;

        default:
          break;
      }
    },
    /** 查询一级经销商列表 */
    getList() {
      this.loading = true;
      listDealerph(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
        this.dealerList = response.rows;
        this.total = response.total;
        this.loading = false;
        console.log(this.dealerList);
      });
    },

    /** 分配按钮操作 */
    deafp(row) {
      this.idsdeaid = row.deaId;
      this.open1 = true;
      this.title = "分配业务员";
      this.getListuser();
    },
    handlejsy(row) {
      this.idsdeaid = row.deaId;
      this.open1 = true;
      this.title = "分配技术员";
      this.getListuserjs();
    },
    /** 查询分配列表 */
    getListuser() {
      this.loading = true;
      listuser(this.queryParamsUser).then(response => {
        this.dealeruser = response.rows;

        //这里查询子表中绑定的数据，将选中项显示绑定
        this.deauserparm.deaId = this.idsdeaid;
        listDealeruser(this.deauserparm).then(responseuser => {
          this.$nextTick(() => {
            this.dealeruser.forEach(row => {
              for (var i in responseuser.rows) {
                if (responseuser.rows[i].userId == row.userId) {
                  this.$refs.multipleTable.toggleRowSelection(row, true);
                }
              }
            });
          }
          )
          this.loading = false;
        });

      });
    },
    /** 查询技术员分配列表 */
    getListuserjs() {
      this.loading = true;
      listuser(this.queryParamsUser).then(response => {
        this.dealeruser = response.rows;
        //这里查询子表中绑定的数据，将选中项显示绑定
        this.deauserparm.deaId = this.idsdeaid;
        listDealeruserjs(this.deauserparm).then(responseuser => {
          this.$nextTick(() => {
            this.dealeruser.forEach(row => {
              for (var i in responseuser.rows) {
                if (responseuser.rows[i].userId == row.userId) {
                  this.$refs.multipleTable.toggleRowSelection(row, true);
                }
              }
            });
          }
          )
          this.loading = false;
        });
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    cancel1() {
      this.open1 = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        deaId: null,
        deaName: null,
        deaUser: null,
        deaPassword: null,
        deaPeople: null,
        deaTel: null,
        deaEmail: null,
        deaAddress: null,
        deaType: null,
        deaState: "0",
        createUser: null,
        editUser: null,
        createTime: null,
        editTime: null,
        other1: null,
        other2: null,
        other3: null,
        other4: null,
        other5: null,
        dtype: null,
      };
      this.form.dtype = this.$route.query.a;
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 搜索按钮操作 */
    handleUserQuery() {

      this.getListuser();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    /**分配窗口重置 */
    resetQueryUser() {
      this.resetForm("queryFormUser");
      this.handleUserQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.deaId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    // 渠道状态修改
    handleStatusChange(row) {
      let text = row.status === "0" ? "启用" : "停用";
      this.$modal.confirm('确认要"' + text + '""' + row.deaName + '"用户吗？').then(function () {
        return changeUserStatus(row.userId, row.status);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function () {
        row.status = row.status === "0" ? "1" : "0";
      });
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.deadis = false;
      this.open = true;
      this.title = "添加渠道信息";

    },

    //跳转到客户页面
    findkh: function (row) {

      let routeData = this.$router.resolve({ path: '/client/customerinfoph', query: { did: row.deaId, } });
      window.open(routeData.href, '_blank');
      // this.$router.push(
      //   {
      //     path: '/client/customerinfo',
      //     methods: 'post',
      //     query: {
      //       did: row.deaId,
      //     }
      //   })
    },
    /** 分配搞操作 */
    ImportClick() {

      const orderIds = this.ywyid; //选中的用户

      this.deaval.deaIdpa = this.ywyid;
      this.deaval.deaIdpb = this.ywyname;
      this.deaval.deaIdpc = this.ywycode;
      this.deaval.deaId = this.idsdeaid;
      if (this.title == "分配技术员") {

        selectyhjs(this.deaval).then(response => {
          this.open1 = false;
          this.$modal.msgSuccess("分配成功");
          this.getList();
        });
      }
      else {
        selectyh(this.deaval).then(response => {
          this.open1 = false;
          this.$modal.msgSuccess("分配成功");
          this.getList();
        });
      }

    },
    // 分配弹窗多选框选中数据1
    handleSelectionChangeUser(selection) {
      this.ywyid = selection.map(item => item.userId)
      this.ywyname = selection.map(item => item.nickName)
      this.ywycode = selection.map(item => item.userName)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      this.deadis = true;
      const deaId = row.deaId || this.ids;
      getDealer(deaId).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改渠道信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.deaId != null) {
            updateDealer(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addDealer(this.form).then((response) => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const deaIds = row.deaId || this.ids;

      this.$modal
        .confirm('是否确认删除经销商编号为"' + deaIds + '"的数据项？')
        .then(function () {
          return delDealer(deaIds);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "DealerMain/dealer/export",
        {
          ...this.queryParams,
        },
        `dealer_${new Date().getTime()}.xlsx`
      );
    },
    /** 同步经销商 */
    tbDeal(tblx) {
      if (tblx == "1")
        this.queryParams.other1 = "1";
      else
        this.queryParams.other1 = "2";
      this.loading = true;
      tblistDealer(this.queryParams).then((response) => {
        this.queryParams.other1 = null;
        this.getList();

        this.loading = false;
      });
    },

    //渠道详情相关方法
    handlemark: function (row) {
      this.openmark = true;
      this.loadingmark = false;
      this.titlxq = "渠道详情【" + row.deaName + "】";
      this.queryParammark.deaId = row.deaId;
      this.getlistmark();
    },
    getlistmark() {
      listDealermark(this.queryParammark).then(response => {
        this.customerinfomarkList = response.rows;
        this.loadingmark = false;
      });

    },
    /** 新增按钮操作 */
    handleAddmark() {
      this.resetmark();
      this.titlemark = "添加渠道备注";
      this.openmarka = true;
    },
    /** 修改按钮操作 */
    handleUpdatemark(row) {
      this.reset();
      const id = row.id || this.ids
      getDealermark(id).then(response => {
        this.formmark = response.data;
        this.openmarka = true;
        this.titlemark = "修改渠道备注";
      });
    },
    /** 删除按钮操作 */
    handleDeletemark(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除渠道备注编号为"' + ids + '"的数据项？').then(function () {
        return delDealermark(ids);
      }).then(() => {
        this.getlistmark();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    // 取消按钮
    cancelmark() {
      this.openmarka = false;
      this.resetmark();
    },
    /** 提交按钮 */
    submitFormmark() {
      this.formmark.deaId = this.queryParammark.deaId;
      this.$refs["formmark"].validate(valid => {
        if (valid) {
          if (this.formmark.id != null) {
            updateDealermark(this.formmark).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.openmarka = false;
              this.getlistmark();
            });
          } else {
            addDealermark(this.formmark).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.openmarka = false;
              this.getlistmark();
            });
          }
        }
      });
    },
    // 表单重置
    resetmark() {
      this.formmark = {
        id: null,
        deaId: null,
        mark: null,
        other1: null,
        other2: null,
        other3: null,
        other4: null,
        other5: null,
        createUser: null,
        editUser: null,
        createSj: null,
        editSj: null
      };
      this.resetForm("formmark");
    },
  },
};
</script>
<style>
.dotClass {
  width: 10px;
  height: 10px;
  float: left;
  margin-top: 6px;
  border-radius: 50%;
  display: block;

}

.el-table th.gutter {
  display: table-cell !important;
  /* 解决表头线未对齐 */
}
</style>
 